package com.video.web.controller.video;

import com.video.video.domain.DClassifyBach;
import com.video.video.domain.DGoodsBach;
import com.video.video.domain.vo.ClassifyVo;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.video.domain.DClassify;
import com.video.video.service.IDClassifyService;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 分类Controller
 *
 * @author ruoyi
 * @date 2022-09-27
 */
@RestController
@RequestMapping("/video/DClassify")
public class DClassifyController extends BaseController
{
    @Autowired
    private IDClassifyService dClassifyService;

    /**
     * 查询分类列表
     */
    @PreAuthorize("@ss.hasPermi('video:DClassify:list')")
    @GetMapping("/list")
    public TableDataInfo list(DClassify dClassify)
    {
        startPage();
        List<DClassify> list = dClassifyService.selectDClassifyList(dClassify);
        return getDataTable(list);
    }

    /**
     * 获取一级分类集合
     * @return
     */
    @GetMapping("/getlist")
    public TableDataInfo getlist()
    {
        List<ClassifyVo> list = dClassifyService.selectClassifyVoList();
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('video:DClassify:getlistByPid')")
    @GetMapping(value = "getlistByPid/{pid}")
    public AjaxResult getlistByPid(@PathVariable("pid") String pid)
    {
        List<ClassifyVo> list =dClassifyService.getlistByPid(pid);
        return AjaxResult.success(list);
    }

    /**
     * 分类批量启用，禁用
     * @param dClassifyBach
     * @return
     */
    @PreAuthorize("@ss.hasPermi('video:DClassify:editBach')")
    @Log(title = "分类批量启用，禁用", businessType = BusinessType.UPDATE)
    @PutMapping("/enableBach")
    public AjaxResult editBach(@RequestBody DClassifyBach dClassifyBach)
    {
        return toAjax(dClassifyService.updateClassifyStatusBach(dClassifyBach));
    }


    /**
     * 导出分类列表
     */
    @PreAuthorize("@ss.hasPermi('video:DClassify:export')")
    @Log(title = "分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DClassify dClassify)
    {
        List<DClassify> list = dClassifyService.selectDClassifyList(dClassify);
        ExcelUtil<DClassify> util = new ExcelUtil<DClassify>(DClassify.class);
        util.exportExcel(response, list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('video:DClassify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(dClassifyService.selectDClassifyById(id));
    }

    /**
     * 新增分类
     */
    @PreAuthorize("@ss.hasPermi('video:DClassify:add')")
    @Log(title = "分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DClassify dClassify)
    {
        return toAjax(dClassifyService.insertDClassify(dClassify));
    }

    /**
     * 修改分类
     */
    @PreAuthorize("@ss.hasPermi('video:DClassify:edit')")
    @Log(title = "分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DClassify dClassify)
    {
        return toAjax(dClassifyService.updateDClassify(dClassify));
    }

    /**
     * 删除分类
     * 同时删除掉 该分类下的全部商品
     *
     */
    @PreAuthorize("@ss.hasPermi('video:DClassify:remove')")
    @Log(title = "分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dClassifyService.deleteDClassifyByIds(ids));
    }
}
